<<xAct`xCoba`

$PrePrint=ScreenDollarIndices;

DefManifold[M,4,IndexRange[a,f]]

DefMetric[-1, metric[-a,-b],CD,{";","∇"},PrintAs->"g"]

DefTensor[v[a],M]

DefTensor[T[-a,-b],M]

DefBasis[cartesian,TangentM,{0,1,2,3}]

abstract indices

T[-a,-b]v[c]

basis indices

T[-{a,cartesian},-{b,cartesian}]v[{c,cartesian}]

component indices

T[{0,-cartesian},{1,-cartesian}]v[{3,cartesian}]

Basis objects

{Basis[{2,-cartesian},a],Basis[{2,cartesian},-a]}

{Basis[{a,-cartesian},b],Basis[{a,cartesian},-b]}

we can define several basis (distinguished by different colors)

DefBasis[polar, TangentM, {0, 1, 2, 3}, BasisColor -> Blue]

Basis object representing basis change

Basis[{a,polar},-{b,cartesian}]

Basis object are not contracted automatically

T[-a,-b] Basis[{1,-cartesian},a]

%//ContractBasis

separating Basis

T[{0,-cartesian},{2,-cartesian}]

%//SeparateBasis[cartesian]

%%//SeparateBasis[AIndex]

use ToBasis instead of direct rewriting abstract indices to basis indices!!!

this is wrong:

v[-{b,cartesian}] CD[-{a,cartesian}][v[{b,cartesian}]]

it should be:

v[-b] CD[-a][v[b]]
%//ToBasis[cartesian]

actually ToBasis[basis] is equivalent to ContractBasis @ SeparateBasis[basis]

tracing basis contractions

T[-a,-{b,cartesian}]v[{b,cartesian}]

%//TraceBasisDummy

decomposition of tensor T[-a,-b]

T[-a,-b]

%//SeparateBasis[cartesian]

%//TraceBasisDummy

array of components

DefTensor[F[-a,-b],M,Antisymmetric[{-a,-b}]]

F[-{a,cartesian},-{b,cartesian}]

%//ComponentArray

%//ToCanonical//MatrixForm

assigning values to the components

values=Table[i-j,{i,4},{j,4}]

%//MatrixForm

AllComponentValues[F[-{a,cartesian},-{b,cartesian}],values]

list of values of all component (dependent rules reflecting symmetries, independent rules)

TensorValues[F]

only independent rules

Last@TensorValues[F]

example of a typical workflow

AllComponentValues[v[{a,cartesian}],{1,3,5,7}]

F[-a,-b]v[b]

%//DummyToBasis[cartesian]

%//SeparateBasis[cartesian]

%//TraceBasisDummy

%//ToValues

Example: computing curvature tensors for Schwarzschild metric

first, we introduce chart (basis with special properties)

DefChart[coord,M,{0,1,2,3},{t[],r[],θ[],φ[]},ChartColor->RGBColor[0,0.7,0]]

DefConstantSymbol[Mass, PrintAs->"M"]

components of the Schwarzschild metric

metricvalues=DiagonalMatrix[{-(1-2(Mass/(r[]))),(((1-2(Mass/(r[]))))^(-1)),((r[])^2),r[]^2 ((Sin[θ[]])^2)}]

%//MatrixForm

storing the components of the metric in a given basis

MetricInBasis[metric,-coord, metricvalues]

TensorValues[metric]

compute curvature tensors

MetricCompute[metric,coord,All,CVSimplify->Simplify,Verbose->True]

independent components of the Ricci tensor

Last@TensorValues[RicciCD]

Kretschmann scalar

KretschmannCD[]

%//ToValues

independent components of the Riemann tensor

Last@TensorValues[RiemannCD]